package cn.eric.framework.auth.domain;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "e_authority")
@Embeddable
@XmlAccessorType(XmlAccessType.NONE)
public class Authority {
    @Id
    @Column(name = "authority_id", unique = true)
    @XmlAttribute(name = "id")
    private String id;
    @Column(name = "authority_name")
    @XmlAttribute(name = "name")
    private String name;
    @Column(name = "authority_info")
    @XmlAttribute(name = "info")
    private String info;
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "parent")
    private Authority parent = null;
    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @XmlElement(name = "authority")
    private List<Authority> childAuthorities = new ArrayList<>();

    @Override
    public String toString() {
        return "Authority{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", info='" + info + '\'' +
                ", childAuthorities=" + childAuthorities +
                '}';
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public Authority getParent() {
        return parent;
    }

    public void setParent(Authority parent) {
        this.parent = parent;
    }

    public List<Authority> getChildAuthorities() {
        return childAuthorities;
    }

    public void setChildAuthorities(List<Authority> childAuthorities) {
        this.childAuthorities = childAuthorities;
    }
}
